<!DOCTYPE html>
<html>
    <?php
    $base_path = $_SERVER['DOCUMENT_ROOT'] . '/nettbutikk';     //  endre /dev/nettbutikk til din path
    include_once $base_path . "/DB/db.php";
    include_once $base_path . "/class/userClass.php";
    ?>
    <head>
        <title>Nettbutikk</title>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <link rel="stylesheet" type="text/css" href="../CSS/mainFrame.css" />
        <style>
            #newCatButton{
                position:absolute;
                bottom:0;
                border: solid;
                color: red;
                border: solid lavender 1px;
                width: 150px;
                border-radius: 5px;
                height: 25px;
                padding-top: 4px;
            }
        </style>
    </head>
    <body>
        <!-- The sidebar which contains a list of all categories. -->
        <div class="sidebar">
            <h2>Kategorier</h2>
            <?php
            // Get all categories and their contents from the database.
            $categories = $db->query('SELECT * FROM itemcategory WHERE deleted=0');
            // Make Æ, Ø and Å legal in the database.
            // $db->query('SET NAMES UTF8');
            // Display a table with the names of the categories:
            echo '<table id="sidebarTable">';
            while ($row = $categories->fetch()) {
                $category = $row['name'];           // Get the name
                $category = utf8_encode($category); // Make æ,ø,å legal
                $cat_copy = ucwords($category);     // For display only
                
                echo '<tr><td>';
                // Display the categories and send the clicked
                echo '<a href="/Views/category.php?cat=' . urlencode($category) . '">';
                echo '<p>' . $category . '</p></a>';
                echo '</td></tr>';
            }
            echo "</table>";

            if ($user->isLoggedOn() && $user->isAdmin()) { //if admin
                adminNewCat();
            }
            ?>
        </div> <!-- End sidebar -->

    </body>
    <?php

    function adminNewCat() {
        echo '<div id="newCatButton" onClick="document.location.href=\'/adminViews/adminCategory.php?alterCat=newCat\'; " style="cursor:pointer;cursor:hand">Lag ny Kategori</div>';
    }
    ?>
</html>
